#include <iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int a[5]={0};
		int count=0;
		for(int i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==1) count++;
		}
		cout<<count<<endl;
	}
}
